/*
 * File    = /src/views/mark/meditor/components/PictureList/items/AnnotationItem.js
 * Time    = 2021-09-09 17=13=12
 * Author  = Gray Snail
 * Version = 1.0
 * Contact = shtao2011@sina.com
 * License = Copyright (c) 2021 Gray Snail
 * Desc    = None
 */

/**
 * 文件类型
 */
export const FileType = Object.freeze({
  D2: '2d',
  D3: '3d',
})

/**
 * 标注类型
 */
export const AnnoType = Object.freeze({
  RECT: 'rect',
  RECT_PT: 'rectPoint1',
  POLYLINE: 'line',
  POLYGON: 'poly',
  UNKNOWN: 'unknown',
})

/**
 * 数据状态
 */
export const ActionStat = Object.freeze({
  NO_CHANGE: '',
  /** 新增 */
  NEW: 'new',
  /** 更新 */
  UPDATE: 'update',
  /** 删除 */
  DELETE: 'delete',
})

export class Annotation {
  // db fields
  mMarkAnnotationId = null
  mQaResultId
  name
  x
  y
  z
  a1
  a2
  a3
  a4
  a5
  a6
  a7
  a8
  b1
  b2
  b3
  b4
  b5
  b6
  b7
  b8
  labels
  fileType
  fileName

  // 状态,new/deleted/update
  selected = false
  status = ActionStat.NEW

  /**
   *
   * @param {String} zType
   * @param {String} filename
   * @param {String} type
   * @param {String|Number} mQaResultId
   */
  constructor(zType, filename, type, mQaResultId) {
    this.z = zType
    this.fileName = filename
    this.fileType = type
    this.mQaResultId = mQaResultId
  }

  static fromData(options) {
    // options = JSON.parse(JSON.stringify(options))
    console.log(options)
    const annotation = new Annotation(options.z, options.fileName, FileType.D2, options.mQaResultId)
    const parsePoint = (x) => {
      return String(x)
        .slice(0, x.length - 1)
        .split(';')
        .map((i) => Number(i))
    }
    annotation.status = ActionStat.NO_CHANGE
    annotation.name = options.name
    annotation.mMarkAnnotationId = options.mMarkAnnotationId
    annotation.x = parsePoint(options.x)
    annotation.y = parsePoint(options.y)
    for (let i = 1; i < 8; i++) annotation['a' + i] = options['a' + i]
    console.log(annotation)
    return annotation
  }

  toDb() {
    console.log('转换为DB数据')
  }
}
